Processing Instructions

You have been dealing with processing instructions since the creation of your first XML document.  If you will recall, processing instructions begin with an opening tag of <? and end with a closing tag of ?>.  The processing instruction that you are already familiar with is the one that declares your document as XML.

<?xml version=”1.0”?>

XML is designed to be generic.  However, being that the technology world that we live in cannot be generic all of the time, processing instructions are there for application specific purposes.  In our XML declaration, we are telling the XML processor (a specific application) that the following content is formatted for XML.  What if we wanted to add some JavaScript or VBScript to our XML that would be processed by our application.  This is a perfect application for a processing instruction.

<?xml version=”1.0”?>
<doc>
	<?javascript  function func1( y ) { ?>
	<?javascript      var x;            ?>
	<?javascript      x = y * 10;       ?>
	<?javascript      return ( x );     ?>
	<?javascript  }                     ?>

	<?vbscript    Sub Sub1( y )         ?>
	<?vbscript        y = y * 10        ?>
	<?vbscript    End Sub               ?>
</doc>

File: Chapter 3\ProcessingInstructions.xml

There aren’t any restrictions on what you can put in a processing instruction.  XML processors do not validate the contents outside of making sure that the name (e.g. javascript, vbscript, etc.) complies with standard naming rules.